import { statisticTeamWeekTotalFlowApi } from '../../api/statistic'

const initOption = () => {
  return {
    title: {
      text: '本周日累计流量对比'
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '4%',
      containLabel: true
    },
    tooltip: {},
    xAxis: { type: 'category' },
    yAxis: {
      name: '流量/m³',
      splitLine: {
        show: false
      },
      axisLine: {
        show: true
      }
    }
  }
}
const apdaterOption = (dom) => {
  const titleFontSize = (dom.offsetWidth / 100) * 1.5
  return {
    title: {
      textStyle: {
        fontSize: titleFontSize
      }
    },
    legend: {
      itemWidth: titleFontSize,
      itemHeight: titleFontSize,
      itemGap: titleFontSize / 2
    },
    yAxis: {
      nameTextStyle: {
        fontSize: titleFontSize.value
      }
    }
  }
}
const dataOption = async (teamId) => {
  const { data: res } = await statisticTeamWeekTotalFlowApi(teamId)
  const data = res.data
  const sourceLength = data.dayNameList.length
  const dataListLength = data.pipelineTotalFlowList.length
  const source = []
  const series = []
  const pipelines = []
  pipelines[0] = data.dataName
  for (let i = 0; i < dataListLength; i++) {
    pipelines.push(data.pipelineTotalFlowList[i].name)
    series.push({
      type: 'bar',
      stack: data.pipelineTotalFlowList[i].stationId
    })
  }
  source.push(pipelines)
  for (let i = 0; i < sourceLength; i++) {
    const dataList = []
    dataList.push(data.dayNameList[i])
    for (let j = 0; j < dataListLength; j++) {
      dataList.push(data.pipelineTotalFlowList[j].weekTotalFlow[i])
    }
    source.push(dataList)
  }
  return {
    dataset: {
      source: source
    },
    series: series,
    legend: {
      show: dataListLength > 0
    }
  }
}

export { initOption, apdaterOption, dataOption }
